using ProtoBuf;
using Arcane.Source.Data.Settings;
using System.IO;

namespace Arcane.Source.Data
{
    [ProtoContract]
    public struct SettingsData
    {
        [ProtoMember(1)]
        public string profileName;
        [ProtoMember(2)]
        public VisualData visual;

        public static SettingsData Load(string path)
        {
            var bytes = Godot.FileAccess.GetFileAsBytes(path);
            return bytes.Length > 0 ? Serializer.Deserialize<SettingsData>(new MemoryStream(bytes)) : new();
        }

        public readonly void Save(string path)
        {
            using var mem = new MemoryStream();
            Serializer.Serialize(mem, this);
            using var file = Godot.FileAccess.Open(path, Godot.FileAccess.ModeFlags.Write);
            file.StoreBuffer(mem.ToArray());
        }
    }
}